"use strict";

module.exports = {
    description:'获取API接口树形结构',
    handler(req, res, next) {
        req.mongo.collection("api").aggregate([
            {$sort: {app: 1, route: 1}},
            {
                $group: {
                    _id: {route: "$route"},
                    items: {$addToSet: {_id: "$_id",open:"$open",security :"$security", description:"$description",extend:"$extend" }}
                }
            },
            {$project:{_id:0,route:"$_id.route",items:"$items"}}
        ]).toArray((err, r)=> {
            if (err)return res.err.errorMongo(err);

            res.reply(r);
        })
    }
};
